package o;

import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import java.util.List;

public class dbf {
    long ʻ = 0;
    long ʽ = 0;
    int ˊ;
    int ˋ;
    int ˎ;
    long ˏ = 0;
    int ॱ;

    public String toString() {
        return "SizeHolder{totalSize=" + this.ˋ + ", installSize=" + this.ॱ + ", downloadSize=" + this.ˊ + ", wifiReserveSize=" + this.ˎ + ", totalUpdateSize=" + this.ˏ + ", leftUpdateSize=" + this.ʽ + ", totalSaveSize=" + this.ʻ + '}';
    }

    static dbf ˋ(List<ApkUpgradeInfo> list) {
        dbf o_dbf = new dbf();
        o_dbf.ˋ = list.size();
        for (ApkUpgradeInfo apkUpgradeInfo : list) {
            if (apkUpgradeInfo != null) {
                o_dbf.ˏ += apkUpgradeInfo.ʻॱ();
                if (apkUpgradeInfo.ʼ() > 0) {
                    o_dbf.ʻ += apkUpgradeInfo.ʻॱ() - apkUpgradeInfo.ʼ();
                    o_dbf.ʽ += apkUpgradeInfo.ʼ();
                } else {
                    o_dbf.ʽ += apkUpgradeInfo.ʻॱ();
                }
                if (dao.ˏ().ˎ() != null) {
                    SessionDownloadTask ˏ = dao.ˏ().ˎ().ˏ(apkUpgradeInfo.ᐝ());
                    if (ˏ != null) {
                        if (ˏ.ˈ() == -1) {
                            o_dbf.ˎ++;
                        } else {
                            ˋ(o_dbf, ˏ, apkUpgradeInfo);
                        }
                    }
                }
                ॱ(o_dbf, apkUpgradeInfo);
            }
        }
        return o_dbf;
    }

    private static void ॱ(dbf o_dbf, ApkUpgradeInfo apkUpgradeInfo) {
        int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(apkUpgradeInfo.ᐝ());
        if (ˋ == 1) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                czi.ˎ.ˊ("SizeHolder", "refreshLocalData InterruptedException");
            }
            ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(apkUpgradeInfo.ᐝ());
        }
        switch (ˋ) {
            case -2:
            case 1:
            case 2:
                ˎ(o_dbf, apkUpgradeInfo);
                return;
            case 0:
                o_dbf.ˋ--;
                return;
            case 10:
            case 11:
                o_dbf.ॱ++;
                ˎ(o_dbf, apkUpgradeInfo);
                return;
            default:
                return;
        }
    }

    private static void ˎ(dbf o_dbf, ApkUpgradeInfo apkUpgradeInfo) {
        if (apkUpgradeInfo.ʼ() > 0) {
            o_dbf.ʽ -= apkUpgradeInfo.ʼ();
        } else {
            o_dbf.ʽ -= apkUpgradeInfo.ʻॱ();
        }
    }

    private static void ˋ(dbf o_dbf, SessionDownloadTask sessionDownloadTask, ApkUpgradeInfo apkUpgradeInfo) {
        switch (sessionDownloadTask.ˈ()) {
            case -1:
            case 0:
            case 1:
            case 2:
            case 8:
                o_dbf.ˊ++;
                ˊ(o_dbf, sessionDownloadTask, apkUpgradeInfo);
                return;
            case 6:
                ˊ(o_dbf, sessionDownloadTask, apkUpgradeInfo);
                return;
            case 7:
                List ᐝˊ = sessionDownloadTask.ᐝˊ();
                if (ᐝˊ != null && ᐝˊ.size() > 0) {
                    o_dbf.ʽ -= ((SplitTask) ᐝˊ.get(0)).ʻ();
                }
                o_dbf.ॱ++;
                return;
            default:
                return;
        }
    }

    private static void ˊ(dbf o_dbf, SessionDownloadTask sessionDownloadTask, ApkUpgradeInfo apkUpgradeInfo) {
        if (apkUpgradeInfo.ʼ() <= 0 || sessionDownloadTask.ˋˊ() <= apkUpgradeInfo.ʼ()) {
            o_dbf.ʽ -= sessionDownloadTask.ˋˊ();
        } else {
            o_dbf.ʽ -= apkUpgradeInfo.ʼ();
        }
    }
}
